package com.gilight.base.controller;

import com.gilight.base.admin.categor.AdminCategoryService;
import com.gilight.base.admin.freight.AdminFreightTemplateService;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import com.gilight.base.dto.goods.AdminSpuDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author liken
 * 商品管理控制类
 */
@RestController
@RequestMapping("/web/admin-freight")
public class AdminFreightController {

    @Autowired
    private AdminFreightTemplateService adminFreightTemplateService;

    /**
     * 后台低频接口，无需缓存，用于选择商品，需要

     * @return
     */
    @ApiOperation(value = "运费列表")
    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    public ResultEntity list(Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminFreightTemplateService.list(adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }


    /**
     * 创建1
     * @return
     */
    @ApiOperation(value = "创建")
    @RequestMapping(value = "/create", method = {RequestMethod.GET})
    public ResultEntity create(
            String title,
            String spuLocation,
            Integer deliveryDeadline,
            Integer defaultFreePrice,
            Integer defaultFirstWeight,
            Integer defaultFirstPrice,
            Integer defaultContinueWeight,
            Integer defaultContinuePrice,
            List carriageDOList,
            Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminFreightTemplateService.create(title,spuLocation,deliveryDeadline,defaultFreePrice
            ,defaultFirstWeight,defaultFirstPrice,defaultContinueWeight,defaultContinuePrice,carriageDOList,adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        };
        return resultEntity;
    }




    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public ResultEntity delete(
            Long id,
            Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminFreightTemplateService.delete(id,adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

    @ApiOperation(value = "更新")
    @RequestMapping(value = "/edit")
    public ResultEntity edit(
            Long id,
            String title,
            String spuLocation,
            Integer deliveryDeadline,
            Integer defaultFreePrice,
            Integer defaultFirstWeight,
            Integer defaultFirstPrice,
            Integer defaultContinueWeight,
            Integer defaultContinuePrice,
            List carriageDOList,
            Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminFreightTemplateService.edit(id,title,spuLocation,deliveryDeadline,defaultFreePrice
                    ,defaultFirstWeight,defaultFirstPrice,defaultContinueWeight,defaultContinuePrice,carriageDOList,adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }
}
